package com.dgut.controller;

import com.dgut.Dto.SearchDto;
import com.dgut.entity.Record;
import com.dgut.entity.User;
import com.dgut.service.AdminService;
import com.dgut.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class AdminController {

    @Autowired
    AdminService adminService;

    @Autowired
    RecordService recordService;


    @PostMapping("/searchHanded")
    public List<Record> searchHanded(@RequestBody SearchDto searchDto){
        if (searchDto.getSearchSchool().size() == 0) {
            return recordService.getRecordByDate(searchDto.getSearchDate());
        } else {
            return recordService.getRecordBySchoolAndDate(searchDto.getSearchSchool().get(1), searchDto.getSearchDate());
        }


    }

    @PostMapping("/searchPersonInfoNoHand")
    public List<User> searchPersonInfoNoHand(@RequestBody SearchDto searchDto) {
        if (searchDto.getSearchSchool().size() == 0) {
            return adminService.getLackUserByDate(searchDto.getSearchDate());
        } else {
            return adminService.getLackUserBySchool(searchDto.getSearchSchool().get(1), searchDto.getSearchDate());
        }
    }
}